﻿<%@ Page Title="" Language="C#" MasterPageFile="~/My/My.master" AutoEventWireup="true"
	CodeBehind="Home.aspx.cs" Inherits="OpenPhotoAlbum.My.Home" %>
<%@ Register Assembly="OpenPhotoAlbum" Namespace="OpenPhotoAlbum.Controls" TagPrefix="cc" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ph1">
	<script language="javascript" type="text/javascript">
		function textChanged(sender, e) {
			var field = e.contextData1;
			var albumId = e.contextData2;
			var clientIds = e.contextData3.split('|');
			var lastModificationLabelId = clientIds[0];
			var hlAlbumId = clientIds[1]
			var text = e.newText;
			var context = new Array(field, albumId, lastModificationLabelId, sender._labelElement.id, hlAlbumId, text);
			if (field == "title") {
				OpenPhotoAlbum.My.Albums.UpdateAlbumTitle(albumId, text, onSuccess, onFail, context);
			}
			else if (field == "description") {
				OpenPhotoAlbum.My.Albums.UpdateAlbumDescription(albumId, text, onSuccess, onFail, context);
			}
			sender._labelElement.innerHTML = "<%= Resources.Strings.Saving %>";
		}
		function onSuccess(result, context) {
			var field = context[0];
			var albumId = context[1];
			var lastModificationLabelId = context[2];
			var labelElementId = context[3];
			var hlAlbumId = context[4];
			var text = context[5];
			setText($get(labelElementId), text);

			if (field == 'title') {
				var arr = result.split('|');
				var linkLocation = arr[0];
				var lastModified = arr[1];
				$('#' + hlAlbumId).attr('href', linkLocation);
				$('#' + lastModificationLabelId).html(lastModified);
			}
			else if (field == 'description') {
				$('#' + lastModificationLabelId).html(result);
			}
		}
		function onFail(param) {}
		function copy() {
			var addr = getText($get('address'));
			copyToClipboard(addr);
		}
		$(function() {
			if (jQuery.browser.safari) {
				$('table.item').each(function() { $(this).css('display', 'inline-table'); });
			}
			else if (jQuery.browser.mozilla) {
				$('table.item').each(function() { $(this).css('display', 'inline-block'); });
			}
		});
	</script>
	
	<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
		<Scripts>
			<asp:ScriptReference Path="~/Controls/CommonScripts.js" />
		</Scripts>
	</asp:ScriptManagerProxy>

	<div class="home"><div class="albums">

		<cc:TabPanels ID="tabPanels" runat="server" CssClass="tabPanels" />
		
		<cc:TabPanel ID="pnlCreateNewAlbum" runat="server" CssClass="createNewAlbum">
			<asp:Literal ID="ltrAlbumTitle" runat="server" />
			<asp:TextBox ID="tbAlbumTitle" runat="server" />
			<asp:Button ID="btnCreateAlbum" runat="server" />
		</cc:TabPanel>
		
		<cc:TabPanel ID="pnlSharingAddress" runat="server" CssClass="sharingAddress">
			<div class="explanation"><%= Resources.Strings.SharingAddress_Explanation %></div>
			<div id="address" class="address"><asp:Literal ID="ltrSharingAddress" runat="server" /></div>
			<div class="btn">
				[<asp:HyperLink ID="hlVisit" runat="server" Target="_blank" />]
				[<a href="javascript:copy();"><%= Resources.Strings.CopyToClipboard %></a>]
			</div>
		</cc:TabPanel>
		
		<div id="items" class="items"><asp:Repeater ID="rptAlbums" runat="server">
			<ItemTemplate>
				<table class="item" cellpadding="0" cellspacing="0"><tr><td>
					<span class="thumbnail"><asp:HyperLink ID="hlAlbum" runat="server" /></span>
					<span class="title"><cc:InplaceEditLabel ID="lblTitle" runat="server" OnClientTextChanged="textChanged" /></span>
					<span class="description"><cc:InplaceEditLabel ID="lblDescription" runat="server" OnClientTextChanged="textChanged" /></span>
					<span class="creationDate"><asp:Label ID="lblCreationDate" runat="server" /></span><span class="lastModifionDate"><asp:Label ID="lblLastModificationDate" runat="server" /></span>
					<span class="commands"><cc:AlbumCommandLinkButton ID="linkBtnDelete" runat="server" /></span>
				</td></tr></table>
				<cc:TooltipExtender ID="ttTitle" runat="server" TargetControlID="lblTitle" Position="Right" />
				<cc:TooltipExtender ID="ttDescription" runat="server" TargetControlID="lblDescription" Position="Right" />
				<cc:TooltipExtender ID="ttDelete" runat="server" TargetControlID="linkBtnDelete" />
			</ItemTemplate>
		</asp:Repeater></div>
		
		<asp:Panel ID="pnlTooltipParent" runat="server" />

	</div></div>
</asp:Content>
